Skip to content

MappedCheckBox

Base classes

Name Children Inherits
CheckBox
prettyqt.widgets.checkbox
Checkbox with a text label.

⋔ Inheritance diagram

graph TD
  3583033269["custom_widgets.MappedCheckBox"]
  1721116053["widgets.CheckBox"]
  2670709832["widgets.AbstractButtonMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  4127570263["QtWidgets.QCheckBox"]
  4168111313["QtWidgets.QAbstractButton"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  1721116053 --> 3583033269
  2670709832 --> 1721116053
  829357528 --> 2670709832
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  2751680898 --> 2670709832
  4127570263 --> 1721116053
  4168111313 --> 4127570263
  3620195106 --> 4168111313
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: CheckBox

Source code in prettyqt/custom_widgets/editors/mappedcheckbox.py
class MappedCheckBox(widgets.CheckBox):
    def __init__(
        self,
        *args,
        true_value=True,
        false_value=False,
        object_name: str = "mapped_checkbox",
        **kwargs,
    ):
        import bidict

        super().__init__(*args, object_name=object_name, **kwargs)
        dct = {True: true_value, False: false_value}
        self.map = bidict.bidict[bool, Any](dct)

    def get_value(self):
        return self.map[self.isChecked()]

    def set_value(self, value):
        val = self.map.inverse[value]
        super().set_value(val)

:fa-brands-github: Show source on GitHub